$(document).ready(function(){
	$(".btn_withdrawRequest").bind("click", function(e){
		var accountNumber = $(this).attr("data-withdrawAccountNumber");
		$("#popup_withdrawRequest").fadeIn("fast", function(){
			$(".moneyWithdraw").html("");
			$(".validBalanceWithdraw").html("");
			$(".money_transaction").val("");
			$.ajax({ 
		        type: 'get', 
		        url: 'requestTransaction', 
		        data:{
		        	accountNumber : accountNumber,
		        },
		        dataType: 'json',
		        success: function (data) { 
					console.log(data);
					
					$(".accountNumber").html(data.accountNumber);
					$(".accountType").html(data.accountType);
					$(".accountState").html(data.accountState);
					$(".balance").html(data.balance);
					$(".fullName").html(data.idCardNumber.lastName+" "+data.idCardNumber.midName+" "+data.idCardNumber.firstName);
					$(".idCardNumber").html(data.idCardNumber.idCardNumber);
		        }
		    });
		});	
	});
	$("#form_withdrawRequest").submit(function(e){
		e.preventDefault();
			$.ajax({ 
		        type: 'post', 
		        url: 'withdrawConfirm', 
		        data: {
		        	"moneyWithdraw" : $("[name='moneyWithdraw']").val(),
		        	"accountNumber" : $("[class='accountNumber']").html(),
		        },
		        dataType: 'json',
		        success: function (data) { 
					if (data.error =="validWithdraw") {
						$("#popup_withdrawRequest").fadeIn();
						$(".validBalanceWithdraw").html("Money Withdraw > Current Balance");
					} else {
						
						$(".moneyWithdraw").html("");
						$(".validBalanceWithdraw").html("");
						$("#popup_withdrawRequest").fadeOut();
						$("#popup_withdrawConfirm").fadeIn("fast", function(){
						
					$(".accountType").html(data.account.accountType);
					$(".accountState").html(data.account.accountState);
					$(".accountNumber").html(data.account.accountNumber);
					$(".idCardNumber").html(data.account.idCardNumber.idCardNumber);
					$(".moneyWithdraw").html(data.moneyTransaction);
					$(".fullName").html(data.account.idCardNumber.lastName+" "+data.account.idCardNumber.midName+" "+data.account.idCardNumber.firstName);
					$(".balance").html(data.account.balance);
					$(".moneyRemainWithraw").html(data.moneyRemain);
						 }); 
		        }
			}
		   
		}); 
		
	});
		
	


	$("#btn_withdrawComplete").bind("click",function(e){
		$("#popup_withdrawConfirm").fadeOut();
		$("#popup_withdrawComplete").fadeIn("fast", function(){
			$.ajax({ 
		        type: 'post', 
		        url: 'withdrawComplete', 
		        data: {
		        	"moneyWithdraw" : $("[class='moneyWithdraw']").html(),
		        	"accountNumber" : $("[class='accountNumber']").html(),
		        },
		        dataType: 'json',
		        success: function (data) { 
					$(".message").html(data.message);
					$(".error").html(data.error);
					$(".validation").html(data.validation);
				},
				error:function(e) { 
					console.log(e);
				}
		    });
		}); 	
	});	
	
	$("#btn_withdrawConfirm_close").bind("click", function(e){
		$("#popup_withdrawComplete").fadeOut();
	});
	
	$("#btn_withdrawConfirm_cancel").bind("click", function(e){
		$("#popup_withdrawConfirm").fadeOut();
	});

		
	$("#btn_withdrawRequest_cancel").bind("click", function(e){
		$("#popup_withdrawRequest").fadeOut();
	});
	
	
});